package com.leyou.item.dto;

import com.leyou.common.dto.BaseDTO;
import com.leyou.common.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class SpecGroupDTO extends BaseDTO {

    private Long id;
    /**
     * 商品分类id，一个分类下有多个规格组
     */
    private Long categoryId;
    /**
     * 规格组的名称
     */
    private String name;

    /**
     * 规格参数数组
     */
    private List<SpecParamDTO>paramDTOs;

    public SpecGroupDTO(BaseEntity entity){
        super(entity);
    }

    public static <T extends BaseEntity> List<SpecGroupDTO> convertEntityList(Collection<T> list) {
        if(list == null){
            return Collections.emptyList();
        }
        return list.stream().map(SpecGroupDTO::new).collect(Collectors.toList());
    }
}
